﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Utils;

public partial class ajax_user : Page
{
    // Fields
    public Maticsoft.BLL.UserInfo userbll = new Maticsoft.BLL.UserInfo();
    public Maticsoft.Model.UserInfo usermodel = new Maticsoft.Model.UserInfo();

    // Methods
    public int GetEmail(string email)
    {
        this.usermodel = this.userbll.GetEmail(email);
        if (this.usermodel != null)
        {
            return 1;
        }
        return 0;
    }

    public int GetUserName(string name)
    {
        this.usermodel = this.userbll.Getusername(name);
        if (this.usermodel != null)
        {
            return 1;
        }
        return 0;
    }

    protected override void OnLoad(EventArgs e)
    {
        Json json;
        base.OnLoad(e);
        string str = Helper.GetString(base.Request["n"], string.Empty);
        string email = Helper.GetString(base.Request["v"], string.Empty);
        switch (str)
        {
            case "signupemail":
                json = new Json("", "");
                json.error = this.GetEmail(email);
                base.Response.Clear();
                base.Response.Write(WebSiteHelper.GetJson(json));
                base.Response.End();
                break;

            case "signupusername":
                json = new Json("", "");
                json.error = this.GetUserName(email);
                base.Response.Clear();
                base.Response.Write(WebSiteHelper.GetJson(json));
                base.Response.End();
                break;
        }
    }

}